package com.banyuan.HomeWork.ArrayTest;

import java.util.Arrays;

/* 有两个整数型一维数组，分别是{3,5,1,7,8,11,22} {2,8,6,4,88,66,44}。

​    12.1 首先循环打印出以上两个数组的所有值。

​    12.2 将以上两个数组复制到一个新的数组中，然后打印出这个新数组的所有值。

​    12.3 对这个新数组排序，打印排序结束的数组中所有值。*/
public class QuestionTwelve {
    public static void main(String[] args) {
        int[] arr1 = new int[]{3, 5, 1, 7, 8, 11, 22};
        int[] arr2 = new int[]{2, 8, 6, 4, 88, 66, 44};
        for (int i = 0; i < arr1.length; i++) {
            System.out.print(arr1[i] + " ");
        }
        System.out.println();
        for (int i = 0; i < arr1.length; i++) {
            System.out.print(arr2[i] + " ");
        }
        System.out.println();


        int[] arr3 = new int[arr1.length + arr2.length];
        System.arraycopy(arr1, 0, arr3, 0, arr1.length);
        System.arraycopy(arr2, 0, arr3, arr1.length, arr2.length);
        System.out.println(Arrays.toString(arr3));

        for (int i = 0; i < arr3.length - 1; i++) {
            for (int j = 0; j < arr3.length - 1 -i; j++) {
                if (arr3[j] > arr3[j + 1]) {
                    int temp = arr3[j];
                    arr3[j] = arr3[j + 1];
                    arr3[j + 1] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(arr3));

    }
}
